﻿using System;
using System.Collections.Generic;
using System.Text;
using ERP.BusinessEntities.Base;
using ERP.BusinessEntities.Factory;
using ERP.DAL.Base;
using ERP.DAL.Util;

namespace ERP.BusinessEntities
{
    public class Provider
    {
        //public static IDBUtil DBUtil = new SQLDBUtil();
        static Dictionary<String, BaseBusinessController> dicControllers = new Dictionary<string, BaseBusinessController>();

        public static T GetController<T>() where T : BaseBusinessController
        {
            Type type = typeof(T);

            T controller = null;
            if (dicControllers.ContainsKey(type.Name) == false)
            {
                controller = (T)BusinessFactory.CreateBusinessCtrl(type);
                if (controller != null)
                    dicControllers.Add(type.Name, controller);
            }
            else
                controller = (T)dicControllers[type.Name];

            return controller;
        }
    }
}
